package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.GenTable;
import io.mybatis.example.springboot.service.GenTableService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * gen_table - 代码生成业务表
 *
 * @author mkj
 */
@RestController
@RequestMapping("genTables")
public class GenTableController {

  @Autowired
  private GenTableService genTableService;

  @PostMapping
  public DataResponse<GenTableDO> save(@RequestBody GenTableDO genTable) {
    return DataResponse.ok(genTableService.save( genTable));
  }

  @GetMapping
  public RowsResponse<GenTableDO> findList(@RequestBody GenTableDO genTable) {
    return RowsResponse.ok(genTableService.findList( genTable));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<GenTableDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(genTableService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<GenTableDO> update(@PathVariable("id") Long id, @RequestBody GenTableDO genTable) {
    genTable.setId(id);
    return DataResponse.ok(genTableService.update( genTable));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(genTableService.deleteById(id) == 1);
  }

}
